package com.fesine.batch.service.impl;

import com.fesine.batch.dao.IDaoService;
import com.fesine.batch.model.UserPo;
import com.fesine.batch.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2017/2/28 21:57
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/2/28 21:57
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private IDaoService daoService;
    @Override
    public int register(UserPo entity) {
        return daoService.insert(entity);
    }

    @Override
    public int modify(UserPo entity) {
        return daoService.update(entity);
    }

    @Override
    public void delete(String[] ids) {
        UserPo userPo;
        for (String id : ids) {
            userPo = new UserPo();
            userPo.setId(id);
            daoService.delete(userPo);
        }
    }

    @Override
    public boolean login(String username, String password) {
        UserPo userPo = new UserPo();
        userPo.setUsername(username);
        userPo.setPassword(password);
        userPo = daoService.selectOne(userPo);
        return (userPo == null ? false:true);
    }

    @Override
    public boolean checkUsername(String username) {
        UserPo userPo = new UserPo();
        userPo.setUsername(username);
        userPo = daoService.selectOne(userPo);
        return (userPo == null ? false : true);
    }

    @Override
    public UserPo findByUserId(String id) {
        UserPo userPo = new UserPo();
        userPo.setId(id);
        userPo = daoService.selectOne(userPo);
        return userPo;
    }

    @Override
    public List<UserPo> findAll() {
        return daoService.selectList(new UserPo());
    }

    @Override
    public List<UserPo> findAll(int pageNum, int pageSize) {
        return daoService.selectList(new UserPo(), pageNum,pageSize);
    }
}
